app
.controller('YsModalCheckboxCtrl', ['$scope', '$http', YsModalCheckboxController]);
function YsModalCheckboxController($scope, $http){

	var gridId = $scope.gridId;
	$scope.checkbox.ys_sub_grid_checkbox_left_all = false;
	$scope.checkbox.ys_sub_grid_checkbox_right_all = false;
	
	/*
	 * 左边行双击
	 */
	$scope.checkbox.doubleClickLeft = function(data) {
		console.log('---------data--------------', data);
		
		var isAdd = $scope.checkbox.addToRightSingle(data);
		
		if(isAdd == false) {
			layer.msg('该数据已被选中');
		}
	}
	
	/*
	 * 左边添加到右边
	 */
	$scope.checkbox.addToRightSingle = function(data) {
		
		var isAdd = true;
		for (var i = 0; i < $scope.checkbox.rowsSelected.length; i++) {
			var rowSelected = $scope.checkbox.rowsSelected[i];
			if(rowSelected[$scope.checkbox.ukey] == data[$scope.checkbox.ukey]) {
				isAdd = false;
			}
		}
		
		if(isAdd == true) {
			$scope.checkbox.rowsSelected.push(data);
		}
		return isAdd;
	}
	$scope.checkbox.doubleClickRight = function(index) {
		$scope.checkbox.rowsSelected.splice(index, 1);
	}
	
	/*
	 * 单击行（左边）
	 */
	$scope.checkbox.singleClickLeft = function(data, index) {
		var selected = $scope.checkbox.rows[index]['ys_sub_grid_checkbox_left'];
		if(selected) {
			$scope.checkbox.rows[index]['ys_sub_grid_checkbox_left'] = false;
		} else {
			$scope.checkbox.rows[index]['ys_sub_grid_checkbox_left'] = true;
		}
	}
	
	/*
	 * 单击行（右边）
	 */
	$scope.checkbox.singleClickRight = function(data, index) {
		var selected = $scope.checkbox.rowsSelected[index]['ys_sub_grid_checkbox_right'];
		if(selected) {
			$scope.checkbox.rowsSelected[index]['ys_sub_grid_checkbox_right'] = false;
		} else {
			$scope.checkbox.rowsSelected[index]['ys_sub_grid_checkbox_right'] = true;
		}
	}
	$scope.checkbox.leftToRight = function() {
		for (var i = 0; i < $scope.checkbox.rows.length; i++) {
			var row = $scope.checkbox.rows[i];
			if(row.ys_sub_grid_checkbox_left == true) {
				$scope.checkbox.addToRightSingle(row);
			}
		}
	}
	$scope.checkbox.rightToLeft = function() {
		var rowsSelected = [];
		for (var i = 0; i < $scope.checkbox.rowsSelected.length; i++) {
			var rowSelected = $scope.checkbox.rowsSelected[i];
			if(rowSelected.ys_sub_grid_checkbox_right == true) {
			} else {
				rowsSelected.push(rowSelected);
			}
		}
		$scope.checkbox.rowsSelected = rowsSelected;
	}
	
	/*
	 * 确认选中，可自定义回调函数$scope.checkbox.afterSelectDatas
	 */
	$scope.checkbox.confirm = function() {
		$scope.checkbox.afterSelectDatas($scope.checkbox.rowsSelected);
		$scope.checkbox.bsObj.hide();
	}
	$scope.checkbox.doSelected = function(data) {
		// 表单用
		if($scope.checkbox.type == 1) {
			for(var i = 0; i < $scope.rows.length; i++) {
				var row = $scope.rows[i];
				if(row.code == $scope.checkbox.code) {
					$scope.valueMap[row.code] = data[row.modalValueCode];
				} else if(row.modalRelativeCode == $scope.checkbox.code) {
					$scope.valueMap[row.code] = data[row.modalValueCode];
				}
			}
		}
		
		$scope.checkbox.bsObj.hide();
	}
	
	/*
	 * 全选和全不选（左边）
	 */
	$scope.checkbox.checkAllLeft = function() {
		console.log('---------$scope.checkbox.ys_sub_grid_checkbox_left_all--------------', $scope.checkbox.ys_sub_grid_checkbox_left_all);

		for(var i = 0; i < $scope.checkbox.rows.length; i++) {
			$scope.checkbox.rows[i]['ys_sub_grid_checkbox_left'] = $scope.checkbox.ys_sub_grid_checkbox_left_all;
		}
	}
	
	/*
	 * 全选和全不选（右边）
	 */
	$scope.checkbox.checkAllRight = function() {
		console.log('---------$scope.checkbox.ys_sub_grid_checkbox_right_all--------------', $scope.checkbox.ys_sub_grid_checkbox_right_all);
		for(var i = 0; i < $scope.checkbox.rowsSelected.length; i++) {
			$scope.checkbox.rowsSelected[i]['ys_sub_grid_checkbox_right'] = $scope.checkbox.ys_sub_grid_checkbox_right_all;
		}
	}
	
}